package com.ajmd.onlineexam.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import javax.print.Doc;

/**
 * @author ajmd
 * @since 2023/3/8 21:58
 */


@Configuration
@EnableOpenApi
@EnableWebMvc
public class SwaggerConfig {
    @Value("${swagger.basePackage}")
    private String basePackage;       // basePackage指定扫描的包

    @Value("${swagger.title}")
    private String title;           // 自定义当前文档的标题

    @Value("${swagger.description}")
    private String description;         // 自定义当前文档的详细描述

    @Value("${swagger.version}")
    private String version;         // 自定义当前文档的版本
    //自定义作者的信息，包括作者名字、个人主页、邮箱等相关信息
//    @Value("${swagger.name}")
//    private String name;
//    @Value("${swagger.email}")
//    private String email;
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("学生")
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
    }
    @Bean
    public Docket createRestApi1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("分组1");
    }
    @Bean
    public Docket createRestApi2(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("分组2");
    }
    @Bean
    public Docket createRestApi3(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("分组3");
    }

    private ApiInfo apiInfo() {
//        Contact contact = new Contact(name,url,email);
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .version(version)
//                .contact(contact)
                .build();
    }
}